<?php include '../public/header.php' ?>
<?php include '../public/header_public.php' ?>
<style>
    #curmsg{color: red;cursor: pointer;padding: 5px 10px}

    .bkuai{width: 140px;height: 150px;margin-right: 20px;float: left;cursor: pointer;position: relative;border-radius: 5px}
    .bkuai:hover{background-color: #eee;}
    .bkuai:hover .opts{display:block}
    .bkuai img{margin: 10px 30px 0}
    .bkuai .baotit{padding: 0 5px;line-height: 18px;text-align: center;
        display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;
    }
    .bkuai .opts{position: absolute;right: 0;top: 6px;font-size: 14px;color: #0E0EFF;width: 30px;height: 30px;display: none;}
    .bkuai .optlist{position: absolute;right: 13px;top: 25px;background-color: #FFFFFF;border: 1px solid #eeeeee;
        border-radius: 3px;padding: 5px 0;z-index: 99;
    }
    .bkuai .optlist div{margin-top: 5px;padding: 0 20px}
    .bkuai .optlist div:hover{color: #0E0EFF;}
    #kongjia{text-align: center;color: #bbb;margin-top: 100px;}
    #gofan{position: absolute;left: 0;top: 1px;font-weight: bold;color: red;cursor: pointer;font-size: 18px;padding: 2px 4px}

    .banlan{width: 100%;;margin: 0 auto;margin-top: 10px;height: 600px}
    .banlan .lankuai{width: 100%;height: 100%;text-align: center}
    .banlan .lankuai{height: 100%;}
    .banlanbut{position: absolute;right: 40px;top: 0;background-color: #f4f4f4;color: #575757;border: 1px solid #aaa}
    .banlanbut:hover{background-color: #0079fe;color: #FFFFFF;border: 1px solid #0079fe}
    .ffll{float: left}
    #but_chuanbao{height: 30px;line-height: 25px;background: #2272eb;color: #fff;width: 130px;border-radius: 6px;margin-left: 10px}
    #mubanname{line-height: 30px;margin-left: 20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;width: calc(100% - 180px);}
    .landdbao{padding: 0 80px;position: relative}
    .landdbao .baozyb .bbnn{background-color: #f7f4f4;width: 40px;height: 30px;float: left;position: absolute;text-align: center;line-height: 30px;cursor: pointer;}
    .landdbao .baozyb .bbnn:hover{background-color: #eee8e8}
    .landdbao .baozyb .bbleft{left: 0}
    .landdbao .baozyb .bbzuo{left: 40px}
    .landdbao .baozyb .bbyou{right: 40px}
    .landdbao .baozyb .bbright{right: 0}
    #baoinfo{background-color: #f7f4f4;width: 100%;height: 31px;line-height: 31px;overflow-x: auto;white-space: nowrap;overflow-y: hidden}
    #baoinfo::-webkit-scrollbar {display: none;}
    #baoinfo .aann{padding: 0 8px;display: inline-block;max-width: 150px;cursor: pointer;overflow: hidden;white-space: nowrap;
        text-overflow: ellipsis;height: 30px;border-bottom: 1px solid #f7f4f4}
    #baoinfo .aann:hover{background-color: #eee8e8;border-bottom: 1px solid #0079fe}
    #baoinfo .active{background-color: #eee8e8;border-bottom: 1px solid #0079fe}
    .cusseadd {width: 22%!important;}
    .cusseadd .layui-input-block{margin-left: 80px!important;}

    .butmenuhide{display: none}
</style>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">文件上报</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3 cusseadd">
                        <label class="layui-form-label" style="width: 80px!important;">文件名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 cusseadd">
                        <label class="layui-form-label" style="width: 80px!important;">上传人</label>
                        <div class="layui-input-block">
                            <input type="text" name="created_user_name" id="created_user_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 cusseadd">
                        <label class="layui-form-label" style="width: 80px!important;">上传时间</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="created_at" id="created_at" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="muid" name="muid">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" onclick="TableSearchFunc()" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <?php include 'mu.php' ?>
            <div class="layui-col-md9" id="table_list">
                <div class="layui-card-body" style="padding:0 10px;background-color: #FFFFFF;padding: 0!important;">
                    <div id="curmsg" class="layui-hide">有<span id="bonum">0</span>个文件上报被驳回，请重新提交！</div>
                    <div style="clear: both"></div>
                    <div class="lankuai lan_nolan2 xianmu" style="text-align: center"><img src="/static/admin/images/nolan2.png" style="margin-top: 100px;"></div>
                    <div class="lanquanbu layui-hide">
                        <span class="lanbanobj layui-hide"></span>
                        <div class="hhh" style="margin-top: 10px">
                            <button class="layui-btn layui-btn-sm laytp-container-tool-button ffll" id="but_chuanbao" onclick="auth_but_func_chuanbao('上传文件')" style="padding-right: 12px;">上传文件</button>
                            <div id="mubanname" class="ffll"></div>
                        </div>
                        <div style="clear: both"></div>
                        <div class="banlan">
                            <div class="lankuai lan_img"><img id="nanimgs" src="" style="height: 100%"></div>
                            <div class="lankuai layui-hide lan_pdf"><iframe src="" frameborder="0" width="100%" height="100%"></iframe></div>
                            <div class="lankuai layui-hide lan_doc"><iframe src="" frameborder="0" width="100%" height="100%"></iframe></div>
                            <div class="lankuai layui-hide lan_video">
                                <video controls autoplay style="width: 100%;height: 100%">
                                    <source src="" type="video/mp4">
                                </video>
                            </div>
                            <div class="lankuai lan_nolan"><img src="/static/admin/images/nolan.png" style="margin-top: 100px;"></div>
                        </div>
                        <button class="layui-btn layui-btn-sm banlanbut" id="banlanbutdom">操 作</button>
                        <div class="landdbao">
                            <div class="baozyb">
                                <div class="bbnn bbleft" key="bbleft" title="左到底">|<</div>
                                <div class="bbnn bbzuo" key="bbzuo" title="向左"><</div>
                                <div class="bbnn bbyou" key="bbyou" title="向右">></div>
                                <div class="bbnn bbright" key="bbright" title="右到底">|></div>
                            </div>
                            <div id="baoinfo">
                                <!-- <div class="aann active">哈哈通知书通知书哈.doc</div>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <input type="file" id="uploadfile" style="display: none"/>
    <input type="hidden" id="upload_muid" datatype="">
    <input type="hidden" id="copyid" datatype="">
    <input type="hidden" id="mubanid">
</div>
<script>

    $(".bbnn").click(function () {
        var key = $(this).attr('key');
        var box = document.getElementById('baoinfo');
        var boxGun = box.scrollLeft;
        var rr = 500;

        if(key == 'bbleft'){
            box.scrollTo({left: 0, behavior: 'smooth'});
        }
        if(key == 'bbzuo'){
            box.scrollTo({left: boxGun-rr, behavior: 'smooth'});
        }
        if(key == 'bbyou'){
            box.scrollTo({left: boxGun+rr, behavior: 'smooth'});
        }
        if(key == 'bbright'){
            box.scrollTo({left: box.scrollWidth, behavior: 'smooth'});
        }
    });

    function TableSearchFunc() {
        var name = $("#name").val() || '';
        var created_user_name = $("#created_user_name").val() || '';
        var created_at = $("#created_at").val() || '';
        if(!name && !created_user_name && !created_at){
            facade.error('请输入搜索内容');return false;
        }
        openPage('tan_info.php');
    }


    $("#curmsg").click(function () {
        openPage('tan_info.php');
    });



    function render_caozuo(bandata){
        if(bandata.type == 'bao' && bandata.status != 1){
            var menudata = [
                {title: '详细信息',id: 'show'},
                {title: '下载',id: 'down'},
            ];

            if(check_caoauth('shen')){
                menudata.push({title: '审核',id: 'shen'});
            }
        }else{
            var menudata = [
                {title: '详细信息',id: 'show'},
                {title: '下载',id: 'down'},
            ];
        }


        if(check_caoauth('edit')){
            menudata.push({title: '编辑',id: 'edit'});
        }
        if(check_caoauth('delete')){
            menudata.push({title: '删除',id: 'delete'});
        }



        layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
            var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form,
                soulTable = layui.soulTable;



            var caomenus = dropdown.render({
                elem: '#banlanbutdom'
                ,data: menudata
                ,click: function(data, othis){
                    var funcname = data.id;
                    if(bandata.type == 'ban'){
                        if(funcname == 'show'){
                            openPageEdit('../engin_baoku/showmu.php?close=1&id='+bandata.id);
                        }
                        if(funcname == 'edit'){
                            openPageEdit('../engin_baoku/edit_ban.php?close=1&id='+bandata.id);
                        }
                        if(funcname == 'down'){
                            public_down_ban_file(bandata.encpath)
                        }
                        if(funcname == 'delete'){
                            data_delete_cur(ask_engin_mu_del, {id:bandata.id});
                        }
                    }else{
                        if(funcname == 'show'){
                            openPageEdit('../engin_bao/show.php?close=1&id='+bandata.id);
                        }
                        if(funcname == 'shen'){
                            openPageEdit('../engin_bao/show.php?close=1&shen=1&id='+bandata.id);
                        }
                        if(funcname == 'edit'){
                            openPageEdit('../engin_bao/edittwo.php?close=1&muid='+bandata.pid+'&id='+bandata.id);
                        }
                        if(funcname == 'down'){
                            public_down_bao_file(bandata.encpath)
                        }
                        if(funcname == 'delete'){
                            data_delete_cur(ask_engin_bao_del, {id:bandata.id});
                        }
                    }
                }
            });
            $('#banlanbutdom').data('layui_dropdown_index', caomenus.config.id); // 替代修改源码的那句的作用

            render_from();
        });
    }


    var param_enginid = getQueryVariable('id') || 0;
    var user_token_roletype, butauth;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $("#uploadfile").change(function () {
            var loading = layui.layer.load(0, {shade: 0.1});
            let fd = new FormData();
            for (var i = 0; i < this.files.length; i++) {
                fd.append('files[]', this.files[i]);
            }
            fd.append('token', facade.getCookie('token'));
            fd.append('enginid', param_enginid);
            var muid = $("#upload_muid").val() || 0;
            fd.append('muid', muid);
            $.ajax({
                url: server_api_name+ask_engin_bao_add,
                type: "POST",
                data: fd,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (res) {
                    $("#uploadfile").val();
                    layui.layer.close(loading);
                    facade.success("提交成功!");
                    setTimeout(() => {
                        get_mu_info(muid);
                    }, 1500);
                },
                error: function (res) {
                    $("#uploadfile").val();
                    layui.layer.close(loading);
                    facade.error("网络错误");
                },
            })
        });
    });





    function setWenList(data){
        $("#upload_muid").val(data.id);
        data.type = 'ban';
        if(data.ismu < 1){
            $(".xianmu").removeClass('layui-hide');
            $(".lanquanbu").addClass('layui-hide');
            return '';
        }else{
            $(".xianmu").addClass('layui-hide');
            $(".lanquanbu").removeClass('layui-hide');
        }
        setYulanMuban(data)
    }

    function qieShowBao(obj) {
        $("#baoinfo").find('.aann').removeClass('active');
        $(obj).addClass('active');
        var baodata = JSON.parse($(obj).find('.baoobj').text());
        setYulanMuban(baodata);
    }


    function setBaoinfo(baninfo) {
        facade.ajax({url: ask_engin_mu_xiabao_list, data:{muid: baninfo.id,enginid:param_enginid,haveshen:1}}).done(function(res){
            if (res.code === 2000) {

                var list = res.data.list;
                var str = '';
                for (var key in list){
                    if(list[key].type == 'ban'){
                        $("#mubanname").html('<span title="'+list[key].parentsName+'">'+'/ '+list[key].parentsName+'</span>');
                    }
                    if(key < 1){
                        str += '<div class="aann active" onclick="qieShowBao(this)" title="'+list[key].title2+'">';
                    }else{
                        str += '<div class="aann" onclick="qieShowBao(this)" title="'+list[key].title2+'">';
                    }
                    str += '<span>'+list[key].title+'</span>';
                    str += '<span class="baoobj layui-hide">'+JSON.stringify(list[key])+'</span>';
                    str += '</div>';
                }
                $("#baoinfo").html(str);

                render_from();
            }
        });
    }

    function setYulanMuban(data) {
        if(data.type == 'ban'){
            setBaoinfo(data);
        }
        $("#mubanid").val(data.id).attr('datatype',data.type);
        $("#mubanname").html('<span title="'+data.parentsName+'">'+'/ '+data.parentsName+'</span>');
        $(".lanquanbu").removeClass('layui-hide');


        $(".lanbanobj").text(JSON.stringify(data));

        render_caozuo(data);

        $(".lankuai").addClass('layui-hide');
        var ext = data.ext;
        var encpath = data.encpath;

        $(".lan_img").find('img').attr('src', '');
        $(".lan_pdf").find('iframe').attr('src', '');
        $(".lan_doc").find('iframe').attr('src', '');
        $(".lan_video").find('video').attr('src', '');


        if(data.type == 'ban'){
            var setUrl = get_ban_file_complete(encpath);
        }else{
            var setUrl = get_bao_file_complete(encpath);
        }

        if(ext == 'png' || ext == 'pneg' || ext == 'jpg' || ext == 'jpeg' || ext == 'gif'){
            $(".lan_img").removeClass('layui-hide');
            var imgElement = document.getElementById('nanimgs');
            imgElement.src = setUrl
            imgElement.src = imgElement.src + '?timestamp=' + new Date().getTime();

            upload_files_file_viewer('nanimgs');

        }else if(ext == 'pdf'){
            $(".lan_pdf").removeClass('layui-hide');
            $(".lan_pdf").find('iframe').attr('src', setUrl);
        }else if(ext == 'doc' || ext == 'docx' || ext == 'xls' || ext == 'xlsx' || ext == 'ppt' || ext == 'pptx'){
            layui.use(['laytp'], function() {
                $.ajax({
                    url:get_ban_file_complete(encpath),
                    type:'get',
                    data:{token:facade.getCookie('token')},
                    dataType:'json',
                    async: false,
                    success:function (e) {
                        if(e.code == 2000){
                            var urls = "https://view.officeapps.live.com/op/view.aspx?src="+encodeURI(server_doc_name+e.data);
                            $(".lan_doc").removeClass('layui-hide');
                            $(".lan_doc").find('iframe').attr('src', urls);
                        }
                    }
                });
            });
        }else if(ext == 'mp4'){
            layui.use(['laytp'], function() {
                $.ajax({
                    url:get_ban_file_complete(encpath),
                    type:'get',
                    data:{token:facade.getCookie('token')},
                    dataType:'json',
                    async: false,
                    success:function (e) {
                        if(e.code == 2000){
                            $(".lan_video").removeClass('layui-hide');
                            $(".lan_video").find('video').attr('src', server_doc_name+e.data);
                        }
                    }
                });
            });
        }else{
            $(".lan_nolan").removeClass('layui-hide');
        }



    }
    function close_right_lanban(){
        $("#mubanid").val('');
        $("#mubanname").html('');
        $(".lanquanbu").addClass('layui-hide');
    }









    if(typeof(viewerObj) === "undefined" || typeof(viewerObj) === undefined || viewerObj == null){
        var viewerObj = [];
    }



















    function auth_but_func_downjia(muid){
        facade.ajax({url: ask_engin_mu_down, data: {muid:muid,enginid:param_enginid}}).done(function(res){
            if (res.code === 2000) {
                down_file(res.data);
            }
        });
    }

    function listTableResetFunc() {
        var name = $("#name").val('');
        var created_user_name = $("#created_user_name").val('');
        var created_at = $("#created_at").val('');

        var muid = $("#muid").val();
    }




    function layer_close(){
        try {
            parent.layui.table.reload('datalist');
        }catch (e) {

        }
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    function data_delete_cur(url, data, tit='', exp='', width='', height=''){
        if(!tit){
            tit = '是否确认删除？';
        }
        if(!exp){
            exp = '删除后不可恢复，请谨慎删除';
        }
        if(!width){
            width = '450px';
        }
        if(!height){
            height = '220px';
        }
        layer.confirm("<div class='tit'>"+tit+"</div><div class='exp'>"+exp+"</div>", {
                title:'操作确认',
                icon: 3,
                area:[width,height],
                btn:['确定']
            }, function(conindex){
                facade.ajax({url: url, data:data}).done(function(res){
                    if (res.code === 2000) {
                        facade.success("提交成功!");
                        var muid = $("#muid").val() || 0;
                        get_mu_info(muid);
                        layer.close(conindex);
                    }
                });
            }
        )
    }

    function auth_but_func_chuanbao() {
        $("#upload_muid").attr('datatype', 'bao');
        document.getElementById('uploadfile').value = null;
        $("#uploadfile").click();
    }
    function auth_but_func_guanjia() {
        openPageEdit('guanmu.php?close=1&enginid='+param_enginid);
    }
</script>
</body>
</html>
